<?php
Zend::loadClass('Lead_EDO_Datatype_field');
/**
 * Datatype for datetime
 * 
 * @package EDO
 * @subpackage Datatypes
 *
 */
class Lead_EDO_Datatype_Datetime extends Lead_EDO_Datatype_Field 
{
	protected $_SQLValueIsQuoted = true;

	protected $pattern = '/^\d{4}-\d{1,2}-\d{1,2}$|^\d{4}-\d{1,2}-\d{1,2} \d{2}\:\d{2}\:\d{2}$/';
		
	function validate($validate)
	{
		if(is_null($validate) AND !$this->notNull())
			return null;
	
	   if(is_integer($validate))
	   {
	       $validate = date('Y-m-d H:i:s', $validate);
	   }
	      
		if(is_string($validate))
		{
			if(preg_match($this->pattern, $validate))
			{
				return $validate;
			}
		}
	
				
		return false;
	}
	
	
	public function getDisplayValue()
	{
        
	    return preg_replace('/^(\d{4})-(\d{1,2})-(\d{1,2}) (\d{2})\:(\d{2})\:(\d{2})$/', "$3.$2.$1", $this->getValue());	    
	}
	
	
}